package com.weizai.carshop.controller;


import com.weizai.carshop.common.context.BaseContext;
import com.weizai.carshop.common.enumeration.AppHttpCodeEnum;
import com.weizai.carshop.common.result.PageResult;
import com.weizai.carshop.common.result.ResponseResult;
import com.weizai.carshop.model.dto.QueryShopCateDto;
import com.weizai.carshop.model.entiity.CartListEntity;
import com.weizai.carshop.service.CartListService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/cartList")
@RequiredArgsConstructor
public class CartListController {

    private final CartListService cartListService;

    /*
    * 更新购物车
    * */
    @PostMapping
    public ResponseResult updateCart(@RequestBody CartListEntity args) {
        args.setUserId(BaseContext.getCurrentId());
        cartListService.updateCart(args);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    /*
    * 获取购物车
    * */
    @GetMapping
    public ResponseResult queryCartList(QueryShopCateDto dto) {
        PageResult result = cartListService.queryCartList(dto);
        return ResponseResult.okResult(result);
    }
}
